package com.srd.phone.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.shengrongdai.srd.R;
import com.srd.phone.bean.TenderRecordInfo;
import com.srd.phone.utils.views.ViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class TenderRecordAdapter extends BaseAdapter {

    private Context mContext;
    private List<TenderRecordInfo> list = new ArrayList<>();

    public TenderRecordAdapter(Context context) {
        mContext = context;
    }

    public void setData(List<TenderRecordInfo> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TenderRecordInfo info = list.get(position);
        ViewHolder holder = ViewHolder.get(mContext, convertView, parent, R.layout.activity_tender_record_detail_item, position);
        TextView tv_order =  holder.getView(R.id.tv_order);
        TextView tv_invest_people =  holder.getView(R.id.tv_invest_people);
        TextView tv_invest_money =  holder.getView(R.id.tv_invest_money);
        TextView tv_invest_time =  holder.getView(R.id.tv_invest_time);

        tv_order.setText(String.valueOf(position + 1));
        if (position % 2 == 0) {
            holder.getConvertView().setBackgroundColor(Color.TRANSPARENT);
        } else {
            holder.getConvertView().setBackgroundColor(Color.WHITE);
        }
        if (!TextUtils.isEmpty(info.userName)) {
            String value = info.userName.substring(0, 1);
            tv_invest_people.setText(value + "**");
        } else {
            tv_invest_people.setText("");
        }
        if (info.moneys < 10000) {
            tv_invest_money.setText(info.moneys + "元");
        } else {
            double d = info.moneys / 10000;
            tv_invest_money.setText(d + "万元");
        }
        tv_invest_time.setText(info.stime);
        return holder.getConvertView();
    }
}
